//
//  SelectDeviceVController.m
//  EquesCat
//
//  Created by Chun Hung Cheung on 2025/4/2.
//

#import "SelectDeviceVController.h"
#import "CatDevicesViewController.h"
#import "QRcodeScanViewController.h"
@interface SelectDeviceVController ()

@end

@implementation SelectDeviceVController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [HexChangeRGB colorWithHexString:@"#F5F5F5"];
    [self setup];
    [self get_button_array];
}


- (void)setup
{
     self.title = NSLocalizedString(@"选择设备", nil);
     UIButton *backbtn = [UIButton buttonWithType:UIButtonTypeCustom];
     backbtn.frame = CGRectMake(0,0,80,40);
     backbtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16.0f];
     backbtn.contentHorizontalAlignment =  UIControlContentHorizontalAlignmentLeft;
    [backbtn setImage: [UIImage imageNamed:@"button_back_lightgray_arrow"] forState:UIControlStateNormal];
    [backbtn addTarget:self action:@selector(selectLeftAction) forControlEvents:UIControlEventTouchUpInside];
     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backbtn];
}

- (void)selectLeftAction
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    
    [self.navigationController.navigationBar setBackgroundImage:[Tooles imageWithColor:WXHColor(255, 255, 255, 1.0)] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
     self.navigationController.navigationBar.shadowImage = [Tooles imageWithColor:[HexChangeRGB colorWithHexString:@"#EBEBEB"]];
    [UIApplication sharedApplication].statusBarStyle =  UIStatusBarStyleDefault;
   
   if(@available(iOS 15.0,*)){
     UINavigationBarAppearance *apperance=[[UINavigationBarAppearance alloc]init];
     apperance.backgroundColor = [UIColor whiteColor];//设置背景色
     self.navigationController.navigationBar.standardAppearance = apperance;
     self.navigationController.navigationBar.scrollEdgeAppearance = apperance;
   }
    
}


- (void)get_button_array
{
    NSMutableArray *button_array = [NSMutableArray array];
    

    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:NSLocalizedString(@"智能锁", nil) forKey:@"title"];
    [dict setValue:@"vl0_add_smart_lock"  forKey:@"icon"];
    [dict setValue:@(110) forKey:@"tag"];
    [button_array addObject:dict];
    
    

     NSMutableDictionary *dict2 = [NSMutableDictionary dictionary];
    [dict2 setValue:NSLocalizedString(@"智能宠物", nil) forKey:@"title"];
    [dict2 setValue:@"add_pet_feeder"  forKey:@"icon"];
    [dict2 setValue:@(111) forKey:@"tag"];
    [button_array addObject:dict2];
    
   
    
    for (int i = 0; i < button_array.count; i++){
        
        NSDictionary *dict = button_array[i];
        
        UIButton *value_button = [[UIButton alloc]init];
        value_button.userInteractionEnabled = YES;
        value_button.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
       [value_button setTitleColor:[HexChangeRGB colorWithHexString:@"#666666"] forState:UIControlStateNormal];
       [value_button addTarget:self action:@selector(value_button_click:) forControlEvents:UIControlEventTouchUpInside];
       [self.view addSubview:value_button];
       [value_button mas_makeConstraints:^(MASConstraintMaker *make) {
           
           make.top.equalTo(self.view.mas_top).offset([UIDevice dev_statusBarHeight]+(100+40)*i );
           make.width.mas_equalTo(kScreenWidth-28);
           make.height.mas_equalTo(100);
           make.centerX.equalTo(self.view.mas_centerX);
       }];
        
        [value_button setTitle:[dict objectForKey:@"title"] forState:UIControlStateNormal];
        [value_button setImage:[UIImage imageNamed:[dict objectForKey:@"icon"]] forState:UIControlStateNormal];
        [value_button SG_imagePositionStyle:SGImagePositionStyleTop spacing:8];
         value_button.tag = [[dict objectForKey:@"tag"] intValue];
         value_button.backgroundColor = [UIColor whiteColor];
    }
    
    
}

- (void)value_button_click:(UIButton*)sender
{
    switch (sender.tag) {
        case 110:
        {
            QRcodeScanViewController *code = [[QRcodeScanViewController alloc]init];
            code.hidesBottomBarWhenPushed = YES;
           [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
           [self.navigationController.navigationBar setShadowImage:nil];
           [self.navigationController pushViewController:code animated:YES];
        }
            break;
        case 111:
        {
            CatDevicesViewController *vc = [[CatDevicesViewController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
           [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        default:
            break;
    }
}


@end
